package org.films.web;

import java.lang.Long;
import java.lang.String;
import java.util.Set;
import javax.validation.Valid;
import org.films.domain.Comment;
import org.films.domain.Consumer;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

privileged aspect ConsumerController_Roo_Controller {
    
    @RequestMapping(value = "/consumer/create", method = RequestMethod.POST)    
    public String ConsumerController.create(@Valid Consumer consumer, BindingResult result, ModelMap modelMap) {    
        if (consumer == null) throw new IllegalArgumentException("A consumer is required");        
        if (result.hasErrors()) {        
            modelMap.addAttribute("comments", Comment.findAllComments());            
            return "consumer/create";            
        }        
        consumer.persist();        
        return "redirect:/consumer/" + consumer.getId();        
    }    
    
    @RequestMapping(value = "/consumer/form", method = RequestMethod.GET)    
    public String ConsumerController.createForm(ModelMap modelMap) {    
        modelMap.addAttribute("consumer", new Consumer());        
        modelMap.addAttribute("comments", Comment.findAllComments());        
        return "consumer/create";        
    }    
    
    @RequestMapping(value = "/consumer/{id}", method = RequestMethod.GET)    
    public String ConsumerController.show(@PathVariable("id") Long id, ModelMap modelMap) {    
        if (id == null) throw new IllegalArgumentException("An Identifier is required");        
        modelMap.addAttribute("consumer", Consumer.findConsumer(id));        
        return "consumer/show";        
    }    
    
    @RequestMapping(value = "/consumer", method = RequestMethod.GET)    
    public String ConsumerController.list(@RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, ModelMap modelMap) {    
        if (page != null || size != null) {        
            int sizeNo = size == null ? 10 : size.intValue();            
            modelMap.addAttribute("consumers", Consumer.findConsumerEntries(page == null ? 0 : (page.intValue() - 1) * sizeNo, sizeNo));            
            float nrOfPages = (float) Consumer.countConsumers() / sizeNo;            
            modelMap.addAttribute("maxPages", (int) ((nrOfPages > (int) nrOfPages || nrOfPages == 0.0) ? nrOfPages + 1 : nrOfPages));            
        } else {        
            modelMap.addAttribute("consumers", Consumer.findAllConsumers());            
        }        
        return "consumer/list";        
    }    
    
    @RequestMapping(method = RequestMethod.PUT)    
    public String ConsumerController.update(@Valid Consumer consumer, BindingResult result, ModelMap modelMap) {    
        if (consumer == null) throw new IllegalArgumentException("A consumer is required");        
        if (result.hasErrors()) {        
            modelMap.addAttribute("comments", Comment.findAllComments());            
            return "consumer/update";            
        }        
        consumer.merge();        
        return "redirect:/consumer/" + consumer.getId();        
    }    
    
    @RequestMapping(value = "/consumer/{id}/form", method = RequestMethod.GET)    
    public String ConsumerController.updateForm(@PathVariable("id") Long id, ModelMap modelMap) {    
        if (id == null) throw new IllegalArgumentException("An Identifier is required");        
        modelMap.addAttribute("consumer", Consumer.findConsumer(id));        
        modelMap.addAttribute("comments", Comment.findAllComments());        
        return "consumer/update";        
    }    
    
    @RequestMapping(value = "/consumer/{id}", method = RequestMethod.DELETE)    
    public String ConsumerController.delete(@PathVariable("id") Long id, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size) {    
        if (id == null) throw new IllegalArgumentException("An Identifier is required");        
        Consumer.findConsumer(id).remove();        
        return "redirect:/consumer?page=" + ((page == null) ? "1" : page.toString()) + "&size=" + ((size == null) ? "10" : size.toString());        
    }    
    
    @RequestMapping(value = "/consumer/find/most_active", method = RequestMethod.GET)    
    public String ConsumerController.findMostActiveUser(ModelMap modelMap) {    
        modelMap.addAttribute("users", Consumer.findMostActiveUsers());        
        return "consumer/most_active";        
    }               
}
